#!/usr/bin/env python

import sh
import sys

import argparse
import os.path
from pwn import *


parser = argparse.ArgumentParser()
parser.add_argument('targets', metavar="D", type=str, nargs="+",
                    help="files to pack for backup" )

parser.add_argument("-o", dest="dest", default=".",
                    help="directory to store backups")

args = parser.parse_args()

if not os.path.isdir(args.dest):
    parser.exit(1, "-o must be followed by a directory\nAborted.\n")

for target in args.targets:
    if not os.path.exists(target):
        log.warn("File '{}' not exists".format(target))
        continue
    log.info("Backing up {}".format(target))
    sh.tar("-cvzf", os.path.join(args.dest, "{}.tar.gz".format(target)), target)
